//
//  XLChannelHeaderView.m
//  XLChannelControlDemo
//
//  Created by MengXianLiang on 2017/3/3.
//  Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import "XLChannelHeader.h"

@interface XLChannelHeader ()
{
    UILabel *_titleLabel;
    
    UIButton *_subtitleButton;
}
@end

@implementation XLChannelHeader

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self buildUI];
    }
    return self;
}

-(void)buildUI
{
    CGFloat marginX = 15.0f;
    
    CGFloat labelWidth = (self.bounds.size.width - 2*marginX)/2.0f;
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(marginX, 0, labelWidth, self.bounds.size.height)];
    _titleLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    
    _subtitleButton = [[UIButton alloc] initWithFrame:CGRectMake(labelWidth + marginX, 0, labelWidth, self.bounds.size.height)];
    [_subtitleButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    _subtitleButton.titleLabel.textAlignment = NSTextAlignmentRight;
    [_subtitleButton.titleLabel setFont:[UIFont systemFontOfSize:15.0f]];
    [self addSubview:_subtitleButton];
    [_subtitleButton addTarget:self action:@selector(subTittleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)setTitle:(NSString *)title
{
    _title = title;
    _titleLabel.text = title;
    
}

-(void)setSubTitle:(NSString *)subTitle
{
    _subTitle = subTitle;
//    _subtitleLabel.text = subTitle;
    [_subtitleButton setTitle:subTitle forState:UIControlStateNormal];
}
-(void)subTittleBtnAction:(UIButton *)sender{
    NSString *selectCountStr = nil;
    if (sender.selected) {
        sender.selected = NO;
        selectCountStr = @"0";
    }else{
        sender.selected = YES;
        selectCountStr = @"1";
    }
    if (_editBlock) {
        _editBlock(selectCountStr);
    }
}


@end
